import { apiAddReceiveRed, apiRedImages } from '../../api/index'
import { getRoute } from '../../common/js/mixin'
let page = {
  /**
   * 页面的初始数据
   */
  data: {
    show: false,
    showImg: false,
    isLoaded: false,
    goodsHeight: 0,
    loads: true
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad (options) {
    let h = wx.getSystemInfoSync().screenHeight / 2
    this.screenRatio = wx.getSystemInfoSync().screenWidth / 375
    this.setData({
      navHeight: getApp().globalData.navHeight,
      hh: h,
      isIphoneX: getApp().globalData.isIphoneX
    })
    this.getImg()
    this.getRed()
  },
  // 获取图片
  getImg () {
    apiRedImages().then(
      res => {
        this.setData({
          hasImg: res.data,
          loads: false
        })
      }
    )
  },
  // 领取红包
  getRed () {
    apiAddReceiveRed().then(
      res => {
        console.log(res)
        this.setData({
          resData: res.data
        })
      }
    ).catch(
      res => {
        console.log(res)
        this.setData({
          resData: res.data.data
        })
      }
    )
  },
  // 跳转商品详情
  toUserCenter () {
    wx.switchTab({
      url: '../mine/mine'
    })
  },
  showShare () {
    wx.navigateTo({
      url: '../red-share/red-share'
    })
  }
}
getRoute(page)
Page(page)
